package trabalho3.model;

import java.util.ArrayList;
import java.util.List;

import model.org.jtrace.geometry.Triangle;
import model.org.jtrace.primitives.Point3D;

public class BoundingBox {
	private Point3D lower;
	private Point3D upper;
	private Point3D center;
	
	private List<Triangle> boundingFaces;
	
	public BoundingBox(Point3D lower, Point3D upper) {
		System.out.println(">> BOUNDING BOX");
		
		this.lower = lower;
		this.upper = upper;
		this.center = upper.add(lower).divide(2);
		
		this.boundingFaces = new ArrayList<Triangle>();
		
		MountingFaces();
	}
	
	private void MountingFaces() {
		Point3D v0 = new Point3D(upper.getX(), -1.0*upper.getY(), upper.getZ());
		Point3D v1 = new Point3D(upper.getX(), upper.getY(), upper.getZ());
		Point3D v2 = new Point3D(-1.0*upper.getX(), upper.getY(), upper.getZ());
		Point3D v3 = new Point3D(-1.0*upper.getX(), -1*upper.getY(), upper.getZ());
		
		Point3D v4 = new Point3D(lower.getX(), lower.getY(), lower.getZ());
		Point3D v5 = new Point3D(-1*lower.getX(), lower.getY(), lower.getZ());
		Point3D v6 = new Point3D(-1*lower.getX(), -1*lower.getY(), lower.getZ());
		Point3D v7 = new Point3D(lower.getX(), -1*lower.getY(), lower.getZ());
		
		Triangle t0 = new Triangle(v0, v1, v2, null);
		boundingFaces.add(t0);
		
		Triangle t1 = new Triangle(v1, v2, v3, null);
		boundingFaces.add(t1);
		
		Triangle t2 = new Triangle(v5, v0, v3, null);
		boundingFaces.add(t2);
		
		Triangle t3 = new Triangle(v3, v4, v5, null);
		boundingFaces.add(t3);
		
		Triangle t4 = new Triangle(v6, v1, v0, null);
		boundingFaces.add(t4);
		
		Triangle t5 = new Triangle(v0, v5, v6, null);
		boundingFaces.add(t5);
		
		Triangle t6 = new Triangle(v7, v2, v1, null);
		boundingFaces.add(t6);
		
		Triangle t7 = new Triangle(v1, v6, v7, null);
		boundingFaces.add(t7);
		
		Triangle t8 = new Triangle(v3, v2, v7, null);
		boundingFaces.add(t8);
		
		Triangle t9 = new Triangle(v7, v4, v3, null);
		boundingFaces.add(t9);
		
		Triangle t10 = new Triangle(v4, v7, v6, null);
		boundingFaces.add(t10);
		
		Triangle t11 = new Triangle(v6, v5, v4, null);
		boundingFaces.add(t11);
	}
	
	public List<Triangle> getBoundingFaces() {
		return boundingFaces;
	}
	
	public Point3D getLower() {
		return lower;
	}
	
	public void setLower(Point3D lower) {
		this.lower = lower;
	}
	
	public Point3D getUpper() {
		return upper;
	}
	
	public void setUpper(Point3D upper) {
		this.upper = upper;
	}
	
	public Point3D getCenter() {
		return center;
	}
	
	public void setCenter(Point3D center) {
		this.center = center;
	}
}
